<%#
 Copyright 2020-2022 sirpdboy Wich <sirpdboy@qq.com>
 https://github.com/sirpdboy/netspeedtest
 Licensed to the public under the Apache License 2.0.
-%>

<script type="text/javascript" src="<%=resource%>/cbi.js?v=1.1"></script>
<%+cbi/valueheader%>
<script type="text/javascript">//<![CDATA[

	var stxhr = new XHR();
	function update_status(field, proto)
	{
		var tool = field.name;
		var addr = field.value;
		var protocol = proto ;
        
		var legend = document.getElementById('test-iperf-legend');
		var output = document.getElementById('test-iperf-output');
		if (legend && output)
		{
			output.innerHTML =
				'<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
				'<%:Waiting for command to complete...%>'
			;

			legend.parentNode.style.display = 'block';
			legend.style.display = 'inline';

			stxhr.post('<%=url('admin/network')%>/test_' + tool + protocol + '/' + addr, { token: '<%=token%>' },
				function(x)
				{
					if (x.responseText)
					{
						legend.style.display = 'none';
						output.innerHTML = String.format('<pre>%h</pre>', x.responseText);
					}
					else
					{
						legend.style.display = 'none';
						output.innerHTML ='</p>  <%:Operation execution complete%></p>';

					}

				}
			);
		}
}
//]]></script>

<form method="post" action="<%=url('admin/network/netspeedtest')%>">
      <table>
        <tr><td  class="cbi-value-title"  ><input style="margin: 5px 0"  type="hidden" value="" name="iperf" />
            <select name="iperf_to" style="width:auto">
              <option value="0" selected="selected"><%:iperfstart%></option>
              <option value="1"><%:iperfstop%></option>
            </select></td>
        <td class="cbi-value-field" style="width:100%;" >
            <input type="button" value="<%:Perform operation%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.iperf,this.form.iperf_to.selectedIndex)" /></td>
        </tr>
        <tr><td  class="cbi-value-title" ><%:iperf3 instructions%></td>
          <td class="cbi-value-field"  ><%:The speed measurement terminal must be in the same LAN as the router that starts the speed measurement%><br /><%:Operation steps: start router speed measurement service download test client run speed measurement client input IP address of router speed measurement service%></td>
        </tr>
        <tr>
          <td class="cbi-value-title"><%:Iperf3 speed measurement software download%></td>
          <td class="cbi-value-field"  >
            <input type="button" class="cbi-button cbi-input-reload" value="<%:Domestic download password:%>cpd6" onclick="javascript:window.open('https://sipdboy.lanzoui.com/b01c3esih','target');" />
            <input type="button" class="cbi-button cbi-input-reload" value="<%:Download from foreign official websites%>" onclick="javascript:window.open('https://iperf.fr/iperf-download.php','target');" /></td>
        </tr>
      </table>
  <fieldset class="cbi-section" style="display:none">
    <legend id="test-iperf-legend">
    <%:Collecting data...%>
    </legend>
    <span id="test-iperf-output"></span>
  </fieldset>
</form>

<%+cbi/valuefooter%>
